package com.example.flowable.car;

import com.example.FlowableDb;
import com.example.mapper.EmpMapper;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * @author wsl
 */
public class FlowableTask extends FlowableDb {

    public FlowableTask(){
        super("car:1:d532aff5-e173-11ec-a19f-ac74b110b28d");
    }

    @Autowired
    private EmpMapper empMapper;

    @Test
    public void completeTask() {
        String taskId = "f673cc72-e175-11ec-b680-ac74b110b28d";
        boolean approved = true;
        taskService
                .setVariable(taskId,"approved",approved);
//        taskService.setVariableLocal(taskId,"approved",approved);

        taskService
                .complete(taskId);
    }

    /**
     * 查询我要处理的任务
     */
    @Test
    public void queryMyEvection() {
        String userId = "3";
        List<Task> list = taskService
                .createTaskQuery()
                .processDefinitionId(processDefinitionId)
                .includeProcessVariables()
                .taskAssignee(userId)
                .list();
        for (Task task : list) {
            Map<String, Object> processVariables = task.getProcessVariables();
            System.out.println("processVariables：" + processVariables);
            System.out.println("task编号：" + task.getId());
            System.out.println("task名称：" + task.getName());
            System.out.println("task：" + task);
//            ProcessInstance processInstance = runtimeService
//                    .createProcessInstanceQuery()
//                    .processInstanceId(task.getProcessInstanceId())
//                    .singleResult();
//            empMapper.selectOne(processInstance.getStartUserId())
        }
    }
}
